<?php
// +----------------------------------------------------------------------
// | YFCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: rainfer <81818832@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\common\controller\BaseController;
use app\common\logic\AdminLogic;

class Login extends BaseController
{
    /**
     * 登录显示
     */
	public function login()
	{
		return $this->fetch();
	}
    /**
     * 登录验证
     */
	public function runlogin()
	{
		if (!request()->isAjax()){
			$this->error("提交方式错误！",url('admin/Login/login'));
		}else{
			$admin_username = input('admin_username');
			$password = input('admin_pwd');
			$admin = new AdminLogic('Admin');
			$jieguo = $admin->_adminLogin($admin_username,$password);
			if(empty($jieguo['err_code'])){
                $goBackUrl = base64_decode(session('admin_go_back_url'));
                // 自动设置登录，不再弹出窗口
                if(count($jieguo['data']['projects']) > 0){
                    $this->setProjectId($jieguo['data']['projects'][0]['id']);
                }
                if (empty($goBackUrl)) {
                    $this->success('恭喜您，登陆成功',url('admin/Index/index'));
                }
                else{
                    $this->success('恭喜您，登陆成功',$goBackUrl);
                }
			}else{
				$this->error($jieguo['msg'],url('admin/Login/login'));
			}
		}
	}
    /**
     * 退出登录
     */
	public function logout()
	{
		session('admin_auth',null);
		session('admin_auth_sign',null);
		cookie('aid', null);
        cookie('signin_token', null);
		$this->redirect('admin/Login/login');
	}
}